package com.credit.jumu.playcard.fragment;

import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.credit.jumu.playcard.R;
import com.credit.jumu.playcard.activity.AboutUsActivity;
import com.credit.jumu.playcard.activity.AuthenticationActivity;
import com.credit.jumu.playcard.activity.BankCardAllActivity;
import com.credit.jumu.playcard.activity.BindingCardActivity;
import com.credit.jumu.playcard.activity.CreditCardAllActivity;
import com.credit.jumu.playcard.activity.SetPayPassActivity;
import com.credit.jumu.playcard.activity.SignActivity;
import com.credit.jumu.playcard.utils.DataSharedPreference;
import com.credit.jumu.playcard.utils.ToastUtil;
import com.credit.jumu.playcard.view.QuitDialog;


/**
 * Created by jpeng on 16-11-14.
 */
public class MySetTabFragment extends Fragment implements View.OnClickListener, QuitDialog.OnClickCallBack {
	TextView torecharge;
	TextView towithdrawals, quit, number;
	RelativeLayout authentication, allBankCard, toaddcredit, tosetpass, toaboutus;
	QuitDialog quitDialog;
	private DataSharedPreference ds;

	@Override
	public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
		View view = inflater.inflate(R.layout.fragment_mysettab, container, false);
		ds = new DataSharedPreference(getActivity());
		torecharge = view.findViewById(R.id.torecharge);
		towithdrawals = view.findViewById(R.id.towithdrawals);
		authentication = view.findViewById(R.id.authentication);
		allBankCard = view.findViewById(R.id.allBankCard);
		toaddcredit = view.findViewById(R.id.toaddcredit);
		tosetpass = view.findViewById(R.id.tosetpass);
		toaboutus = view.findViewById(R.id.toaboutus);
		number = view.findViewById(R.id.number);

		quit = view.findViewById(R.id.quit);
		quit.setOnClickListener(this);
		toaboutus.setOnClickListener(this);
		tosetpass.setOnClickListener(this);
		toaddcredit.setOnClickListener(this);
		allBankCard.setOnClickListener(this);
		torecharge.setOnClickListener(this);
		towithdrawals.setOnClickListener(this);
		authentication.setOnClickListener(this);
		number.setOnClickListener(this);
		return view;
	}

	@Override
	public void onResume() {
		super.onResume();
		if (null == ds) return;
		number.setText(TextUtils.isEmpty(ds.getAccount()) ? "请登录" : ds.getAccount());
	}

	@Override
	public void onClick(View v) {
		switch (v.getId()) {
			case R.id.torecharge://充值
				if (TextUtils.isEmpty(ds.getAccount())) {
					ToastUtil.showShortToast("请先登录");
					return;
				}
				Intent intent = new Intent(getActivity(), BindingCardActivity.class);
				intent.putExtra("type", "recharge");
				startActivity(intent);
				break;
			case R.id.towithdrawals://提现
				if (TextUtils.isEmpty(ds.getAccount())) {
					ToastUtil.showShortToast("请先登录");
					return;
				}
				Intent intent1 = new Intent(getActivity(), BindingCardActivity.class);
				intent1.putExtra("type", "withdrawals");
				startActivity(intent1);
				break;
			case R.id.authentication://基本认证
				if (TextUtils.isEmpty(ds.getAccount())) {
					ToastUtil.showShortToast("请先登录");
					return;
				}
				Intent intent2 = new Intent(getActivity(), AuthenticationActivity.class);
				startActivity(intent2);
				break;
			case R.id.allBankCard://储蓄卡包
				if (TextUtils.isEmpty(ds.getAccount())) {
					ToastUtil.showShortToast("请先登录");
					return;
				}
				Intent intent3 = new Intent(getActivity(), BankCardAllActivity.class);
				startActivity(intent3);
				break;
			case R.id.toaddcredit://信用卡包
				if (TextUtils.isEmpty(ds.getAccount())) {
					ToastUtil.showShortToast("请先登录");
					return;
				}
				Intent intent4 = new Intent(getActivity(), CreditCardAllActivity.class);
				startActivity(intent4);
				break;
			case R.id.tosetpass://交易密码
				if (TextUtils.isEmpty(ds.getAccount())) {
					ToastUtil.showShortToast("请先登录");
					return;
				}
				Intent intent5 = new Intent(getActivity(), SetPayPassActivity.class);
				startActivity(intent5);
				break;
			case R.id.toaboutus://关于我们
				Intent intent6 = new Intent(getActivity(), AboutUsActivity.class);
				startActivity(intent6);
				break;
			case R.id.quit://退出
				if (null == quitDialog) {
					quitDialog = new QuitDialog(getActivity(), MySetTabFragment.this);
				}
				quitDialog.showDialog();
				break;
			case R.id.number://用户名
				if (TextUtils.isEmpty(ds.getAccount())) {
					Intent intent7 = new Intent(getActivity(), SignActivity.class);
					startActivity(intent7);
				}
				break;
		}
	}

	//未登录提示
	public void notLoging() {
		if (TextUtils.isEmpty(ds.getAccount())) {
			ToastUtil.showShortToast("请先登录");
		}
	}

	@Override
	public void onQuitClick() {
		ToastUtil.showShortToast("退出了");
		quitDialog.cancelDialog();
		if (null == ds) return;
		ds.cleanData();
		Intent intent = new Intent(getActivity(), SignActivity.class);
		startActivity(intent);
	}

	@Override
	public void notQuitClick() {
		ToastUtil.showShortToast("不退出了");
		quitDialog.cancelDialog();
	}
}